
#pragma once

#include <chrono>
#include <iostream>

typedef std::chrono::high_resolution_clock __clock;
typedef std::chrono::milliseconds __milliseconds;

/**
 * @file Timing.h
 * @author xingyifan
 * @date 2023-08-14 17:28
 * 
 * @description: 高精度计时器
 */

#define TIMER_START(NAME) \
    auto __TIMER##NAME##_START = __clock::now();

#define TIMER_END(NAME)                                                                                           \
    __clock::time_point __TIMER##NAME##_END = __clock::now();                                                     \
    {                                                                                                             \
        auto d = std::chrono::duration_cast<__milliseconds>(__TIMER##NAME##_END - __TIMER##NAME##_START).count(); \
        std::cout << "Timer " << #NAME << ": " << (d / 1000.0) << "s" << std::endl;                               \
    }